home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / wait.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  119 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: wait.c,v 1.5 1996/10/24 15:50:58 aros Exp $
  4.     $Log: wait.c,v $
  5.     Revision 1.5  1996/10/24 15:50:58  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.4  1996/08/13 13:56:09  digulla
  9.     Replaced AROS_LA by AROS_LHA
  10.     Replaced some AROS_LH*I by AROS_LH*
  11.     Sorted and added includes
  12.  
  13.     Revision 1.3  1996/08/01 17:41:21  digulla
  14.     Added standard header for all files
  15.  
  16.     Desc:
  17.     Lang: english
  18. */
  19. #include <exec/execbase.h>
  20. #include <aros/libcall.h>
  21.  
  22. /*****************************************************************************
  23.  
  24.     NAME */
  25.     #include <clib/exec_protos.h>
  26.  
  27.     AROS_LH1(ULONG, Wait,
  28.  
  29. /*  SYNOPSIS */
  30.     AROS_LHA(ULONG, signalSet, D0),
  31.  
  32. /*  LOCATION */
  33.     struct ExecBase *, SysBase, 53, Exec)
  34.  
  35. /*  FUNCTION
  36.     Wait until some signals are sent to the current task. If any signal
  37.     of the specified set is already set when entering this function it
  38.     returns immediately. Since almost any event in the OS can send a
  39.     signal to your task if you specify it to do so signals are a very
  40.     powerful mechanism.
  41.  
  42.     INPUTS
  43.     signalSet - The set of signals to wait for.
  44.  
  45.     RESULT
  46.     The set of active signals.
  47.  
  48.     NOTES
  49.     Naturally it's not allowed to wait in supervisor mode.
  50.  
  51.     Calling Wait() breaks an active Disable() or Forbid().
  52.  
  53.     EXAMPLE
  54.  
  55.     BUGS
  56.  
  57.     SEE ALSO
  58.     Signal(), SetSignal(), AllocSignal(), FreeSignal()
  59.  
  60.     INTERNALS
  61.  
  62.     HISTORY
  63.  
  64. ******************************************************************************/
  65. {
  66.     AROS_LIBFUNC_INIT
  67.  
  68.     ULONG rcvd;
  69.     struct Task *me;
  70.  
  71.     /* Get pointer to current task - I'll need it very often */
  72.     me=SysBase->ThisTask;
  73.  
  74.     /* Protect the task lists against access by other tasks. */
  75.     Disable();
  76.  
  77.     /* If at least one of the signals is already set do not wait. */
  78.     while(!(me->tc_SigRecvd&signalSet))
  79.     {
  80.     /* Set the wait signal mask */
  81.     me->tc_SigWait=signalSet;
  82.  
  83.     /*
  84.         Clear TDNestCnt (because Switch() will not care about it),
  85.         but memorize it first. IDNestCnt is handled by Switch().
  86.         This could as well be stored in a local variable which makes
  87.         the tc_TDNestCnt field somehow redundant.
  88.     */
  89.     me->tc_TDNestCnt=SysBase->TDNestCnt;
  90.     SysBase->TDNestCnt=-1;
  91.  
  92.     /* Move current task to the waiting list. */
  93.     me->tc_State=TS_WAIT;
  94.     Enqueue(&SysBase->TaskWait,&me->tc_Node);
  95.  
  96.     /* And switch to the next ready task. */
  97.     Switch();
  98.     /*
  99.         OK. Somebody awakened me. This means that either the
  100.         signals are there or it's just a finished task exception.
  101.         Test again to be sure (see above).
  102.     */
  103.  
  104.     /* Restore TDNestCnt. */
  105.     SysBase->TDNestCnt=me->tc_TDNestCnt;
  106.     }
  107.     /* Get active signals. */
  108.     rcvd=me->tc_SigRecvd&signalSet;
  109.  
  110.     /* And clear them. */
  111.     me->tc_SigRecvd&=~signalSet;
  112.  
  113.     /* All done. */
  114.     Enable();
  115.     return rcvd;
  116.     AROS_LIBFUNC_EXIT
  117. }
  118.  
  119.